public class demo13 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Thread t1 = new Thread(()->{
           synchronized(locker1) {
               System.out.println("线程t1拿到locker1~~");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               System.out.println("尝试拿去locker2~~");
               synchronized (locker2) {
                   System.out.println("拿到了");
               }
           }
        });
        Thread t2 = new Thread(()->{
            synchronized(locker2) {
                System.out.println("线程t2拿到locker2~~");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("尝试拿去locker1~~");
                synchronized (locker1) {
                    System.out.println("拿到了");
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
